<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/11/29
 * Time: 18:05
 */

namespace app\api\controller\v1;


use app\api\model\ThirdApp;
use app\api\service\AppToken as AppToken;
use app\api\service\Token as TokenService;
use app\api\service\UserToken;
use app\api\validate\AppTokenValidate;
use app\api\validate\TokenGet;
use app\lib\Exception\ParameterException;

class Token
{
    public function getAppToken($account='', $password=''){
        (new AppTokenValidate())->toCheck();
        $appToken = new AppToken();
        $result = $appToken->get($account, $password);
        return json(['token' => $result]);
    }

    public function get($code = '')
    {
        (new TokenGet())->toCheck();
        $userToken = new UserToken($code);
        $result = $userToken->get();
        return json(['token' => $result]);
    }

    public function verify($token = ''){
        if(!$token){
            throw new ParameterException([
                'info' => 'token参数错误'
            ]);
        }

        $valid = TokenService::verifyToken($token);
        return [
            'isValid' => $valid
        ];
    }

}